<?php
namespace jy_guashop;
defined('BY_JYA') or exit('error');
/*
	挂卖
*/
class gua extends \plugin{
	//计划任务
	public function create($logid=0){
		$isadd=pdo_get('jy_guashop_goods',array('logid'=>$logid,'uniacid'=>$_SESSION['uniacid']));
		if($isadd['id']){
			pdo_update('jy_guashop_goods',array('status'=>1),array('logid'=>$logid,'uniacid'=>$_SESSION['uniacid']));
		}else{
			$log=pdo_get('jy_creditshop_log',array('id'=>$logid,'uniacid'=>$_SESSION['uniacid']));
			$goods=pdo_get('jy_creditshop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$log['goodsid']));
            $oldprice=pdo_getcolumn('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$goods['goodsid']),'costprice');
			$indata=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$log['mid'],
                'goodsid'=>$goods['id'],
				'logid'=>$log['id'],
				'oldprice'=>$oldprice,
				'price'=>$goods['price'],
                'desc'=>$goods['title'],
				'createtime'=>TIMESTAMP,
				'status'=>1,
			);
			$this->insert('goods',$indata);
		}
		$update=array('status'=>8);
		pdo_update('jy_creditshop_log',$update,array('id'=>$logid,'uniacid'=>$_SESSION['uniacid']));
		return true;
	}
	public function tuicreate($logid=0){
		$update=array('status'=>7);
		pdo_update('jy_creditshop_log',$update,array('id'=>$logid,'uniacid'=>$_SESSION['uniacid']));
		pdo_update('jy_guashop_goods',array('status'=>4),array('logid'=>$logid,'uniacid'=>$_SESSION['uniacid']));
		return true;
	}
    //发货
    public function order_send($order_id,$params=array()){
        $update=array(
            'order_status'=>2,
            'sendtime'=>time(),
            'express'=>intval($params['express']),
            'expresssn'=>$params['expresssn'],
        );
        $this->update('canlog',$update,array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
        return true;
    }
    //确认收货，完成订单
    public function order_receive($order_id,$ismsg=false){
        $update=array('order_status'=>3,'time_finish'=>TIMESTAMP);
        $this->update('canlog',$update,array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
        return true;
    }
}